package ocean

import (
	"cid-media-api/api/common"
	"cid-media-api/models"
	"context"
	. "github.com/oceanengine/ad_open_sdk_go/models"
	"net/http"
)

func GetAdvertiserReport(
	account models.MediaAccount,
	startDate string,
	endDate string,
	page int64,
	pSize int64,
	timeGranularity ReportAdvertiserGetV2TimeGranularity,
) *ReportAdvertiserGetV2ResponseData {
	ctx := context.Background()

	fields := []string{
		"cost", "show", "avg_show_cost", "click", "avg_click_cost", "ctr", "convert", "convert_cost",
		"stat_pay_amount", "pay_amount_roi", "total_play", "valid_play",
	}

	res, _ := Call(func() (any, *http.Response, error) {
		return Api.ReportAdvertiserGetV2Api().Get(ctx).
			AccessToken(account.AccessToken).
			AdvertiserId(account.AdvertiserId).
			StartDate(&startDate).
			EndDate(&endDate).
			Fields(fields).
			TimeGranularity(timeGranularity).
			Page(page).
			PageSize(pSize).
			Execute()

	}, common.GetAdvertiserReport())

	if res == nil {
		return nil
	}

	resData := res.(*ReportAdvertiserGetV2Response).Data

	return resData
}
